package com.bupt.service;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Component
public class PrimaryKeyService {
    @PersistenceContext
    private EntityManager entityManager;


    public Integer getPrimaryKey(String key) {
        String sql = "select nextval('" + key + "') from dual";
        Query nativeQuery = entityManager.createNativeQuery(sql);
        String s = nativeQuery.getResultList().get(0).toString();
        return Integer.valueOf(s);
    }
}
